set_project("quickjs")
set_xmakever("2.7.3")

add_rules("mode.debug", "mode.release")
set_policy("build.optimization.lto", true)

-- add_plugindirs("plugins") -- use add_plugindirs add custom task/plugin
includes("xmake/**.lua") -- use includes add custom task/plugin/rules, conflict with add_plugindirs



target("qjs")
  set_kind("shared")
  add_files("quickjs.c", "libregexp.c", "libunicode.c", "cutils.c", "quickjs-libc.c", "libbf.c")
  add_headerfiles("*.h")
  add_includedirs(".")
  -- add_cflags("-g", "-O2", "-DEBUG", {force=true})
  -- if is_plat("macosx") then
  --   set_config("framework", true)
  --   add_values("xcode.framework.infoplist", "Info.plist")
  --   set_kind("binary")
  --   add_links("AppKit")
  -- elseif is_plat("iphoneos", "iphonesimulator") then
  --   set_kind("static")
  --   add_links("UIKit")
  --   set_config("framework", true)
  --   add_values("xcode.framework.infoplist", "Info.plist")
  -- end
  if is_plat("linux") and get_config("arch") == "x86_64" then
    -- 使用 add_toolchain 来设置工具链 在 linux x86 上可以编译 arm,x86, linux arm 上只能编译 arm
    set_arch("x86_64")
    set_toolchains("gcc")
  end
  if is_plat("macosx", "iphoneos", "iphonesimulator") then 
    add_rules("xcode.framework2")
    add_files("Info.plist")
    add_values("xcode.codesign_skip", true)
    if is_plat('iphoneos', 'iphonesimulator') then
      -- add_values("xcode.bundle_identifier", "cn.humphreyd.flujs")
      -- add_values("xcode.codesign_identity", "Apple Development: dang8080@qq.com (LH9A68ZYTJ)")
      -- add_values("xcode.mobile_provision", "Marquis Secondary (Personal Team): cn.humphreyd.flujs")
    end
  elseif is_plat("mingw") then
    -- target:add("defines",  "WIN32_LEAN_AND_MEAN" .. "_WIN32_WINNT=0x0602" )
  end
  on_load(function (target)
    target:add("defines",  "_GNU_SOURCE" )
  end)